package com.zq.sysuser.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zq.sysuser.dao.entity.Useractions;
import com.zq.sysuser.mapper.UseractionsMapper;
import com.zq.sysuser.service.IUseractionsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张乔
 * @since 2024-04-29
 */
@Service
public class UseractionsServiceImpl extends ServiceImpl<UseractionsMapper, Useractions> implements IUseractionsService {


    //    根据条件分页查询日志
    @Override
    public PageInfo<Useractions> getPageLogs(Integer page, Integer limit, String userName) {

        PageHelper.startPage(page, limit);
        List<Useractions> useractionsList = this.list(new LambdaQueryWrapper<Useractions>().
                like(StringUtils.hasText(userName), Useractions::getUsername, userName)
                .orderByDesc(Useractions::getActionTime));
        PageInfo<Useractions> pageInfo = new PageInfo<>(useractionsList);

        return pageInfo;
    }
}
